package com.play.ballen.me.vm

import androidx.lifecycle.MutableLiveData
import com.play.ballen.me.entity.RechargeInfo
import com.play.ballen.network.BallenRxHelper
import com.yuven.appframework.network.RxSchedulerHelper
import com.yuven.appframework.util.addToDisposable
import com.yuven.baselib.utils.Logger

class RechargeVM : MoneyLogVM() {

    val rechargeInfo = MutableLiveData<RechargeInfo>()

    fun recharge() {
        model.recharge()
            .onErrorResumeNext(BallenRxHelper.HttpErrorHandleFunc())
            .compose(BallenRxHelper.transformResponse())
            .compose(RxSchedulerHelper.io_main())
            .subscribe({
                Logger.i("RechargeVM.recharge success")
                rechargeInfo.value = it
            }, { throwable ->
                toastLiveData.value = throwable.message
                Logger.i("RechargeVM.recharge error,msg = ${throwable.message}")
            }).addToDisposable(compositeDisposable)
    }

}